package com.fawvwebanma.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fawvwebanma.entity.Person;
import com.fawvwebanma.mapper.PersonMapper;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jieye.ren
 * @date 2021/3/15
 */
@Component
@Slf4j
public class PersonDao {
    @Autowired
    PersonMapper personMapper;

    public List<Person> getPersonByMapStatusEq1(Map<String, Object> map) {
        map.put("status", 1);
        List<Person> personByName = personMapper.selectByMap(map);
        return personByName;
    }

    public List<Person> getPersonByMap(Map<String, Object> map) {

        List<Person> persons = personMapper.selectByMap(map);
        return persons;
    }

    public void updatePerson(Person person, Map<String, Object> map) {

        UpdateWrapper<Person> updateWrapper = new UpdateWrapper<>();
        updateWrapper.allEq(map);
        personMapper.update(person, updateWrapper);
    }

    public void savePerson(Person person) {
        personMapper.insert(person);
    }
}
